<?php
declare (strict_types=1);

namespace app\admin\controller;

use addons\BuilderPlus\components\Column;
use addons\BuilderPlus\components\Edit;
use addons\BuilderPlus\facade\Table;

class ProductType extends Base
{
    public function getOptions(): array
    {
        return [
            'pk' => 'id',
            'model' => \app\common\model\ProductType::class,
            'validate' => \app\admin\validate\ProductType::class
        ];
    }

    public function index(): string
    {
        return Table::init($this)
            ->setCheckbox(false)
            ->addColumns([
                ['id', 'ID', fn(Column $col) => $col->width(80)],
                ['title', '标题', null, fn(Edit $e) => $e->require()],
                ['describe', '描述', null, fn(Edit $e) => $e->text()],
                ['status', '状态', fn(Column $col) => $col->switch('开启|关闭', '1|0')],
                ['sort', '排序', fn(Column $col) => $col->fastSort(), fn(Edit $e) => $e->number()],
                ['update_time', '更新时间', fn(Column $col) => $col->minWidth(150)]
            ])
            ->addRightButtons(['edit'], 100)
            ->setSortType(['id' => 'asc'])
            ->fetch();
    }
}